//A6报名
// $type 0 跨域  1 不跨域 
function A6_data_up($type, data) {
	var $url
	if($type == 0) {
		$url = 'http://m.tj.dyrs.com.cn/api/user/special_appoint.php';
	} else {
		$url = '/api/user/appoint.php';
	}
	if(!data.phone | !data.phone.match(/^[0-9,-]{7,13}$/)) {
		alert('请填写您的手机号!');
		return false;
	} else {
		$.ajax({
			async: false,
			type: "GET",
			url: $url,
			data: {
				name: data.name,
				phone: data.phone,
				acreage: data.acreage,
				loupan: data.loupan,
				desc: data.desc
			},
			dataType: 'jsonp',
			jsonp: "callback",
			success: function(data) {
				alert(data.msg); //此处代码负责弹出提示信息
			},
			error: function(data) {
				str = JSON.parse(data.responseText); //此处代码负责将名称为data下名为responseText的返回数据转换成JSON格式
				alert(str.msg); //此处代码负责弹出提示信息
			}
		})
	}
}
//速美报名
function sumei_data_up(data_up) {
	if(!data_up.phone | !data_up.phone.match(/^[0-9,-]{7,13}$/)) {
		alert('请填写您的手机号!');
	} else {
		var data = {};
		data["name"] = data_up.name;
		data["phone"] = data_up.phone;
		if(_siteId) {
			data["site_id"] = _siteId;
		}
		if(_resource) {
			data["resource"] = _resource;
		}
		data["enter_url"] = window.location.href;
		if(data.name == '') {
			alert('姓名不能为空！');
			return false;
		}
		if(data.phone == '') {
			alert('电话不能为空！')
			return false;
		}
		$.ajax({
			url: 'http://www.sumeihome.com/api/apply/create',
			dataType: 'jsonp',
			data: data,
			success: function(d) {
				alert(d.description);
				$('body').append('<iframe style="display:none;" src="http://apis.laidx.com/SMS/Send?account=ADDCCC26ED8E4475A8CC23FFD3563D7B&token=bc740993e93c40e58aea7cce93f62fb9&mobile=' + data_up.phone + ',15002238750&content=恭喜您已预约成功！家装顾问会与您联系，请保持手机畅通。详询：400-6911-695【东易日盛】&type=1" width="0" height="0"></iframe>');
			},
			error: function(d) {
				alert(d.description);
				$('body').append('<iframe style="display:none;" src="http://apis.laidx.com/SMS/Send?account=ADDCCC26ED8E4475A8CC23FFD3563D7B&token=bc740993e93c40e58aea7cce93f62fb9&mobile=' + data_up.phone + ',15002238750&content=恭喜您已预约成功！家装顾问会与您联系，请保持手机畅通。详询：400-6911-695【东易日盛】&type=1" width="0" height="0"></iframe>');
			}
		});
	}
}
//if_type 0 是速美 1 是A6
function DATA_UP_LV(if_type, type, data) {
	if(if_type == 0) {
		sumei_data_up(data)
	} else {
		A6_data_up(type, data)
	}
}
/*短信接口*/
var number_lv;

function SMS_phone_lv(data) {
	if(!data.phone_id | !data.phone_id.match(/^[0-9,-]{7,13}$/)) {
		alert("请输入手机号");
	} else {
		if($(data.button_lv).attr("if_id") == 0) {
			do
				number_lv = Math.floor(Math.random() * 10000);
			while (number_lv < 1000)
			var html = '<iframe style="display:none;" src="http://apis.laidx.com/SMS/Send?account=ADDCCC26ED8E4475A8CC23FFD3563D7B&token=bc740993e93c40e58aea7cce93f62fb9&mobile=' + data.phone_id + '&content=【东易日盛】您的验证码为：' + number_lv + '，请在页面中输入完成验证。如非本人操作，请忽略本条信息。&type=1" width="0" height="0"></iframe>';
			var time_lv = data.time;
			$("body").append(html);
			$(data.button_lv).attr("if_id", "1");
			var timer1 = setInterval(function() {
				if(time_lv == 1) {
					$(data.button_lv).attr("if_id", "0");
					$(data.button_lv).val(data.button_text);
					$(data.button_lv).text(data.button_text);
					$(data.button_lv).html(data.button_text);
					clearInterval(timer1);
				} else {
					time_lv = time_lv - 1;
					$(data.button_lv).val("信息已发送(" + time_lv + ")");
					$(data.button_lv).text("信息已发送(" + time_lv + ")");
					$(data.button_lv).html("信息已发送(" + time_lv + ")");
				}
			}, 1000);
		}
	}
}

function SMS_yz_lv(number, function_SMS) {
	if(number_lv == number) {
		function_SMS();
	} else {
		alert("您的验证码错误请注意查收！");
	}
}

function sms_lv(type, if_type, desc) {
	//短信接口调取
	$(".SMS_KV_LV .SMS_button_lv").click(function() {
		SMS_phone_lv({
			'button_lv': $(this),
			'phone_id': $(this).parents(".SMS_KV_LV").children(".SMS_phone_lv").val(),
			'button_text': "获取验证码",
			"time": 60
		});
	});
	//验证过程
	$(".SMS_KV_LV .SMS_button_lv2").click(function() {
		var this_lv = $(this);
		SMS_yz_lv($(this).parents(".SMS_KV_LV").children(".SMS_yz_lv").val(), function() {
			DATA_UP_LV(type, if_type, {
				"name": $(this_lv).parents(".SMS_KV_LV").children(".SMS_name_lv").val(), //名字
				"phone": $(this_lv).parents(".SMS_KV_LV").children(".SMS_phone_lv").val(), //手机号
				"acreage": $(this_lv).parents(".SMS_KV_LV").children(".SMS_acreage_lv").val(), //面积
				"loupan": $(this_lv).parents(".SMS_KV_LV").children(".SMS_loupan_lv").val(), //小区
				'desc': desc
			})
		});
	});
	//验证过程
	$(".SMS_KV_LV .SMS_button_lv3").click(function() {
		DATA_UP_LV(type, if_type, {
			"name": $(this).parents(".SMS_KV_LV").children(".SMS_name_lv").val(), //名字
			"phone": $(this).parents(".SMS_KV_LV").children(".SMS_phone_lv").val(), //手机号
			"acreage": $(this).parents(".SMS_KV_LV").children(".SMS_acreage_lv").val(), //面积
			"loupan": $(this).parents(".SMS_KV_LV").children(".SMS_loupan_lv").val(), //小区
			'desc': desc
		})
	});
}